#include <cstdio>
#include <stdlib.h>
#include "simd_thl.h"
#include "hthread.hpp"
#define noreorder(x) __builtin_protect_v4df(x)
__cpe__ __v4df v_invsqrt(__v4df x) {
  __v4di magic = set1_v4di(0x5fe6ec85e7de30daL);
  __v4di xlong = __builtin_cast_v4df_v4di(x);
  __v4df y = __builtin_cast_v4di_v4df(magic - __builtin_cast_v4df_v4di(__builtin_sw_vcpysd(set1_v4df(0.0), __builtin_cast_v4di_v4df(xlong >> 1))));
  __v4df xhalf = x * 0.5;
  y = noreorder(y * 1.5) - noreorder(xhalf*y)*noreorder(y*y);
  y = noreorder(y * 1.5) - noreorder(xhalf*y)*noreorder(y*y);
  y = noreorder(y * 1.5) - noreorder(xhalf*y)*noreorder(y*y);
  return y;
}

